Imports System.Xml.Serialization
Imports System.Reflection

Namespace Aricie.DNN.Caching

    <XmlInclude(GetType(WrappedDistributedCacheObject))> _
    <Serializable()> _
    Public Class WrappedCacheObject


#Region "Private members"


        Protected _Value As Object

        <NonSerialized()> _
        Private _PersistAppRestart As Boolean


        Protected _AbsoluteExpiration As Date = Cache.NoAbsoluteExpiration
        Protected _SlidingExpriration As TimeSpan = Cache.NoSlidingExpiration
        Private _Priority As System.Web.Caching.CacheItemPriority = CacheItemPriority.Default
        Private _CacheItemVersion As Integer

        <NonSerialized()> _
        Protected _Dependency As CacheDependency

        <NonSerialized()> _
        Protected _ItemRemovedCallBack As CacheItemRemovedCallback




#End Region

#Region "cTors"


        Public Sub New()

        End Sub

        Public Sub New(ByVal value As Object, ByVal persistAppRestart As Boolean)
            Me._Value = value
            Me.PersistAppRestart = persistAppRestart
        End Sub

        Public Sub New(ByVal value As Object, ByVal job As CacheJob)
            Me._Value = value
            If job.Strategy.TimeOutMode = TimeOutMode.Constant Then
                If job.Strategy.DisableSlidingEmulation Then
                    Me._AbsoluteExpiration = Now.Add(TimeSpan.FromSeconds(job.Strategy.TimeOutConstant))
                Else
                    Me._SlidingExpriration = TimeSpan.FromSeconds(job.Strategy.TimeOutConstant)
                End If
            End If
        End Sub

        Public Sub New(ByVal value As Object, ByVal persistAppRestart As Boolean, ByVal objDependency As System.Web.Caching.CacheDependency, ByVal absoluteExpiration As Date, _
                            ByVal slidingExpiration As System.TimeSpan, _
                            ByVal priority As System.Web.Caching.CacheItemPriority, _
                             ByVal onRemoveCallback As System.Web.Caching.CacheItemRemovedCallback)

            Me.New(value, persistAppRestart)
            Me._Dependency = objDependency
            Me._AbsoluteExpiration = absoluteExpiration
            Me._SlidingExpriration = slidingExpiration
            Me._Priority = priority
            Me._ItemRemovedCallBack = onRemoveCallback


        End Sub
#End Region


#Region "Public Properties"

        Public Property CreatedDate As DateTime = DateTime.Now

        <XmlIgnore()> _
        Public ReadOnly Property Value() As Object
            Get
                If Me._Value Is Nothing Then
                    Me.GetValue()
                End If
                Return Me._Value
            End Get
        End Property


        Public Property AbsoluteExpiration() As Date
            Get
                Return _AbsoluteExpiration
            End Get
            Set(ByVal value As Date)
                _AbsoluteExpiration = value
            End Set
        End Property

        Public Property SlidingExpriration() As TimeSpan
            Get
                Return _SlidingExpriration
            End Get
            Set(ByVal value As TimeSpan)
                _SlidingExpriration = value
            End Set
        End Property

        Public Property Priority() As System.Web.Caching.CacheItemPriority
            Get
                Return _Priority
            End Get
            Set(ByVal value As System.Web.Caching.CacheItemPriority)
                _Priority = value
            End Set
        End Property

        Public Property Dependency() As CacheDependency
            Get
                Return _Dependency
            End Get
            Set(ByVal value As CacheDependency)
                _Dependency = value
            End Set
        End Property

        <XmlIgnore()> _
        Public Property ItemRemovedCallBack() As CacheItemRemovedCallback
            Get
                If Me._ItemRemovedCallBack Is Nothing Then
                    Me.GetCallBackDelegate()
                End If
                Return _ItemRemovedCallBack
            End Get
            Set(ByVal value As CacheItemRemovedCallback)
                _ItemRemovedCallBack = value
            End Set
        End Property

        Public Property PersistAppRestart() As Boolean
            Get
                Return _PersistAppRestart
            End Get
            Set(ByVal value As Boolean)
                _PersistAppRestart = value
            End Set
        End Property

        Public Property CacheItemVersion() As Integer
            Get
                Return _CacheItemVersion
            End Get
            Set(ByVal value As Integer)
                _CacheItemVersion = value
            End Set
        End Property


#End Region

        Public Overridable Sub GetValue()
        End Sub

        Public Overridable Sub GetCallBackDelegate()
        End Sub

    End Class
End Namespace
